package com.xhu.configuration;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.io.File;

@Component
public class MyCommandLineRunner implements CommandLineRunner {

    @Value("${conf.filePath}")
    private String filePath;

    @Override
    /**
     *  用于检查并且初始化教学视频目录
     */
    public void run(String... args) throws Exception {
        File filePath = new File(this.getDir());
        if(!filePath.exists()){
            boolean re = filePath.mkdirs();
            if(!re){
                throw new Exception("目录初始化失败！");
            }
        }
    }

    private String getDir(){
        return this.filePath+"/decode";
    }
}
